package com.example.demo.service.impl;

import com.example.demo.dao.UpgradeDao;
import com.example.demo.entity.Edition;
import com.example.demo.entity.response.Response;
import com.example.demo.service.UpgradeService;
import com.example.demo.utils.Version;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 11237
 */
@Service
public class UpgradeServiceImpl implements UpgradeService {

    @Autowired
    private UpgradeDao upgradeDao;


    @Override
    public Response upgrade(Edition edition) {
        Response response = new Response();
        Edition edition1 = upgradeDao.selectEdition(edition);
        Version a = new Version(edition.getVersion());
        Version b = new Version(edition1.getVersion());
        switch (b.compareTo(a)){
            case 1:
                response = Response.success(edition1);
                break;
            case 0 :
                response=Response.error("当前已是最新版本");
                break;
            case -1:
                response = Response.error("错误版本");
                break;
            default:
                response = Response.error("意外情况");
                break;
        }
        return response;
    }
}
